package org.xwb.springcloud.config;


import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.xwb.springcloud.constant.MqConstant;

/**
 * 创建RabbitMQ的配置类
 *
 * @author 10564
 */
@Configuration
public class RabbitmqFanoutConfig {
    @Bean
    public Queue fanoutQueueOne() {
        return new Queue(MqConstant.FANOUT_QUEUE_ONE);
    }

    @Bean
    public Queue fanoutQueueTwo() {
        return new Queue(MqConstant.FANOUT_QUEUE_TWO);
    }

    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(MqConstant.FANOUT_EXCHANGE_NAME);
    }

    //将订阅发布队列one 与该交换机绑定
    @Bean
    public Binding fanoutQueueOneBinding() {
        return BindingBuilder.bind(fanoutQueueOne()).to(fanoutExchange());
    }

    //将订阅发布队列two 与该交换机绑定
    @Bean
    public Binding fanoutQueueTwobinding() {
        return BindingBuilder.bind(fanoutQueueTwo()).to(fanoutExchange());
    }
}